doctype html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
html(xmlns="http://www.w3.org/1999/xhtml")
  head
    meta(http-equiv="Content-Type" content="text/html; charset=utf-8")
    title 我和国旗合个影
    meta(name="viewport" content="width=device-width,initial-scale=1")
    link(rel='stylesheet', href='/stylesheets/flag/reset.css')
    link(rel='stylesheet', href='/stylesheets/flag/style.css')
    script(src='http://7xogoq.com1.z0.glb.clouddn.com/itbserver/api/js/jquery-1.11.0.min.js')
    script.
      function getUploadServer(){return '!{locals.global.upload_sever_url}';};
      function getAPIServer(){return '!{locals.global.api_sever_url}'};
      var gUrl='#{imgUrl}';

  body
    block content

      div.top_black
        img.loading(src="../images/flag/loading.gif")

      div.wrapper
        div.container
          a.pic_01
            img(src="../images/flag/pic_01.png")
          a.pic_02
            img(src="../images/flag/pic_02.png")
          p.message1 虽然此时不在天安门广场看升旗
          p.message2 但我希望与国旗合个影
          input.btn01(type="button" name="upload" id="upBtn" style="width:114px;height:114px;")
          input.btn02(style="-webkit-appearance : none;font-family:微软雅黑; text-align:center;" type="button" name="onetouch" value="一键生成" onclick="doMake()")

      script(src="../javascripts/com/common.js")
      script(src="../javascripts/com/ajaxupload.js")
      script.
        $(function(){
          var url = getUploadServer() +"/upload/user?user_id="+#{uId};
          var option = {};
          option.id = 'upBtn';
          option.url = url;
          option.callback = function (res) {
            if (!res.success) {
              //alert(res.msg);
              setTimeout(function(){     alert(res.msg);      },1);
              return;
            }

            gUrl = res.data.url;
            // 显示图片
            $(".btn01").css("background","url("
                    +gUrl.replace('oss-cn-hangzhou.aliyuncs.com','img-cn-hangzhou.aliyuncs.com')
                    +'@120h_120w_1e_1c.png'+")");
          }
          option.imgExts = ['jpg', 'jpeg', 'png'];
          var uploader = new AjaxUploadEx(option);

          // 显示图片
          if(gUrl && gUrl.length>0) {
            //$(".btn01").css("background","url("+gUrl+")");
          }
          $(".top_black").hide();
        })

        function doMake() {
          $.ajax({
            url: getAPIServer() + "/preview/addFlagProc",
            dataType: 'json',
            data:{
              url:gUrl,
            },
            error: function (err) {
              alert(err);
            },
            success: function (ret) {
              if (ret && ret.success == 1) {
                var retUrl = ret.data.url;

                //window.location.href= getAPIServer()+'/preview/viewFlag?rUrl='+retUrl+'&oUrl='+gUrl;
                window.location.href= getAPIServer()
                        +'/preview/viewFlag?rUrl='
                        +retUrl.substr(Number(retUrl.indexOf('/image/U-161001/'))+15);

              } else if (!ret || ret.success == 0) {
                alert('请重新尝试');
              }
            }
          });
        }
